Single owner chunks are the second type of chunk in swarm (see \ref{sec:single-owner-chunks}). They constitute the basis of swarm feeds.


\begin{definition}[Single owner chunks]\label{def:soc}
\begin{lstlisting}[language=buzz1]
// /soc

// data structure for single owner chunk
define type soc 
    id         [segment size]byte // id 'within' owner namespace
    signature  crypto/signature   // owner attests to <content, id> 
    chunk                         // content: embeds a content chunk

// constructor for single owner chunks
define function create from chunk 
    by @owner crypto/keypair
    on @id [segment size]byte
 as
    @sig = crypto/sign @id and @chunk address by @owner
    soc{ @id, @sig, @chunk }

define function address soc
as
    hash @soc id and @soc signature signer address
    
\end{lstlisting}
\end{definition}

\begin{definition}[Single owner chunk API: retrieval]\label{def:soc-retrieve}
\begin{lstlisting}[language=buzz1]
// /soc

define function retrieve @id [segment size]byte
    by @owner ethereum/address
    ?with key
has api GET on "soc/<owner>/<id>(?key=<key>)"
as
    retrieve hash @id and @owner 
        as soc
            chunk (decrypt with @key if @key)
\end{lstlisting}
\end{definition}


\begin{definition}[Single owner chunk API: storage]\label{def:soc-store}
\begin{lstlisting}[language=buzz1]
// /soc

define function store payload
    on @id [segment size]byte
    by @owner ethereum/address 
    ?over span
has api POST on "soc/<owner>/<id>?span=<span>&encrypt=<encrypt>"
    from <payload> as body
as 
    @span = @payload length if no @span
    @chunk = chunk{ @span, @payload }
    if context encryption then
        @key = encryption.key for @chunk 
        @chunk encrypt= with @key
    @soc = create from @chunk on @id by private key of @owner
    reference{ @soc store address, @key }
             
\end{lstlisting}
\end{definition}
